home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-06-14 | 1.4 KB | 53 lines | [TEXT/Rstr] |
- /*
- JavalogClient.java
-
- A very basic implemtation of a syslog message dispatcher in Java
- using UDP datagram sockets
-
- By Christopher Evans
- Copyright © 1996 Natural Intelligence, Inc.
- */
-
- import java.net.*;
- import java.io.*;
-
- /**
- Implements a basic syslog client, sending data to port 514 on
- the machine whose name is passed in as a command line argument
- */
-
- public class JavalogClient {
-
- public static void main(String args[]) throws Exception
- {
- if(args.length != 2) {
- System.out.println("Usage: JavalogClient <host> <message>");
- System.exit(0);
- }
-
- //Create an InetAddress object and initialize it from the first argument
- //which should be a host name like bart.natural.com
- InetAddress address = InetAddress.getByName(args[0]);
-
- //Find out how long the message is, then copy it from a java.lang.String
- //into an array of bytes to be sent.
- int msg_len = args[1].length();
-
- byte[] message = new byte[msg_len];
-
- args[1].getBytes(0,msg_len, message,0);
-
- //Create a DatagramPacket object with the data that the user wants to send
- DatagramPacket packet = new DatagramPacket(message, msg_len, address, 514);
-
- //Create a new datagram socket to send the packet
- DatagramSocket socket = new DatagramSocket();
-
- //Now actually send the data across the network
- socket.send(packet);
-
- //clean up the socket so it isn't left open
- socket.close();
-
- }
- }